﻿if (typeof iThinkings == 'undefined')
    iThinkings = {};
var iThinkingsLayout="";
iThinkings.Layout = {
    CreateLayout: function () {
        var layoutSetting = {
            name: "outerLayout",
            maskIframesOnResize: true,
            defaults: {
                spacing_open: 0,
                spacing_closed: 3,
                resizable: false,
                closable: false,
                initClosed: false,
                onopen_end: false
            },
            north: {
                size: 87,
                spacing_open: 0
            },
            south: {
                size: 0,
                spacing_open: 0
            },
            east: {
                size: 200,
                spacing_open: 0,
                spacing_closed: 0,
                closable: true,
                initClosed: true
            },
            west: {
                size: 250,
                maxSize: 250,
                resizable: false,
                closable: true,
                initClosed: true,
                onopen_end: true,
                spacing_open: 0,
                spacing_closed: 0,
                togglerLength_open: "100%",
                togglerLength_closed: "100%"
            },
            center: {}
        }
        iThinkingsLayout = $("body").layout(layoutSetting);
    },
    ToggleNorth: function () {
        var height = $(window).height();
        if ($('#arrowNorth').hasClass("NorthClose")) {
            iThinkingsLayout.sizePane('north', 22);
            $("#iMarkets-header").css("display", "none")
            $('#arrowNorth').attr('class', 'NorthOpen');
        }
        else {
            iThinkingsLayout.sizePane('north', 87);
            $("#iMarkets-header").css("display", "block")
            $('#arrowNorth').attr('class', 'NorthClose');
        }
        iThinkings.Layout.ResizeFrameCenter();
        //        iThinkings.Accordion.SetSize();
    },
    Interval: '',
    ResizeFrameCenter: function () {
        //Fix iFrame Height
        var northHeight = iThinkingsLayout.state.north.size;
        var westHeight = $(".ui-layout-west").height();
        //        var accordionHeight = $("ul.accordion > li").size() * ($("ul.accordion li").outerHeight() || 26);
        //        var fixedAccordion = $(window).height() - northHeight - $("#topAccordion").outerHeight() - accordionHeight - 26;
        //        $("ul.accordion li.active ul.MenuMod").css("height", "auto");
        //        $("ul.accordion li.active ul.MenuMod").css("max-height", fixedAccordion + "px");
        //        $("ul.accordion").css("margin-top", fixedAccordion + "px");
        //        if ($("ul.accordion > li").size() == 1) {
        //            $("#arrowWest").hide();
        //            iThinkingsLayout.options.west.spacing_closed = 0;
        //            iThinkingsLayout.options.west.spacing_open = 0;
        //        }

        var top = $(".ui-layout-north").height() + 26;
        $(".ui-layout-west").css("top", top + "px");
        $(".ui-layout-west").height($(window).height() - northHeight - 25)


    },
    WestLayout: {
        WestHide: function () {
            var $center = $(".ui-layout-center-content");
            var $west = $(".ui-layout-west");
            var data_animate = { left: -261 };
            $west.animate(data_animate, 1000, function () {
                $('#arrowWest').attr("Class", "WestOpen");
                $west.attr("isShow", 0);
            });
            iThinkings.Layout.Overlay.Hide({ id: 'Overlay-West', container: '.ui-layout-center-content .iThinkings-iFrame-Container' });
            $center.css({
                width: "100%"
            });
        },
        WestShow: function () {
            var $center = $(".ui-layout-center-content");
            var $west = $(".ui-layout-west");
            var data_animate = { left: 0 };
            $west.animate(data_animate, 1000, function () {
                $('#arrowWest').attr("Class", "WestClose");
                $west.attr("isShow", 1);
            });
            if ($center.attr("isIFunc") == "0") {
                var _width_win = $(window).width();
                var _width_center = _width_win - 261;
                $center.css({
                    width: _width_center + "px",
                    position: "absolute",
                    right: 0,
                    left: ""
                });
            }
            iThinkings.Layout.Overlay.Show({ id: 'Overlay-West', container: '.ui-layout-center-content .iThinkings-iFrame-Container' });
        },
        WestFixed: function ($this) {
            var id = $this.attr("id");
            var $center = $(".ui-layout-center-content");
            var $west = $(".ui-layout-west");
            if (id.indexOf("IFunc_") == -1) {
                var _width_win = $(window).width();
                var _width_center = _width_win - 261;
                $center.css({
                    width: _width_center + "px",
                    position: "absolute",
                    right: 0,
                    left: ""
                });
                $center.attr("isIFunc", 0);
            }
            else {
                $center.css({
                    width: "100%"
                });
                $center.attr("isIFunc", 1);
            }
        },
        WestToggle: function () {
            var $center = $(".ui-layout-center-content");
            var $west = $(".ui-layout-west");
            var isShow = $west.attr("isshow") || '0';
            var left = 0;
            if (isShow == "0") {
                if ($center.attr("isIFunc") == "0") {
                    var _width_win = $(window).width();
                    var _width_center = _width_win - 261;
                    $center.css({
                        width: _width_center + "px",
                        position: "absolute",
                        right: 0,
                        left: ""
                    });
                }
                if ($(".ui-layout-center-content").attr("isIFUNC") != "0") {
                    iThinkings.Layout.Overlay.Show({ showLoading: false, showStop: false, id: 'Overlay-West', container: '.ui-layout-center-content .iThinkings-iFrame-Container' });
                }
            }
            else {
                left = -261;
                iThinkings.Layout.Overlay.Hide({ id: 'Overlay-West', container: '.ui-layout-center-content .iThinkings-iFrame-Container' });
                $center.css({
                    width: "100%"
                });
            }
            var data_animate = { left: left };
            $west.animate(data_animate, 1000, function () {
                $('#arrowWest').toggleClass("WestOpen WestClose");
                $west.attr("isShow", Math.abs(isShow - 1));
            });
        },
        Init: function () {
            var thisObj = this;
            var $west = $(".ui-layout-west");
            $west.show().css({
                "top": "113px",
                "left": "-261px",
                "width": "250px",
                "box-shadow": "10px 5px 5px #888"
            });
            $('#arrowWest').click(function () {
                thisObj.WestToggle();
            });
            $('.MenuIFunc a,#Arrow-WestClose').live('click', function () {
                thisObj.WestHide();
            });
        }

    },
    Overlay: {
        Reposition: function (obj, options) {
            var defaults = {
                top: 0,
                left: 0,
                container: $(window)
            };
            options = $.extend({}, defaults, options);
            var $container = options.container;
            var top = (($container.height() / 2) - ($(obj).height() / 2)) + options.top;
            var left = (($container.width() / 2) - ($(obj).width() / 2)) + options.left;
            if (top < 0) top = 0;
            if (left < 0) left = 0;

            // IE6 fix
            if ($.browser.msie && parseInt($.browser.version) <= 6)
                top = top + $(window).scrollTop();

            $(obj).css({
                top: top + 'px',
                left: left + 'px'
            });
        },
        Show: function (options) {
            var thisObj = this;
            var defaults = {
                id: "overlay-default",
                container: "body",
                transparent: true,
                loading: '<div class="iThinkings-loading"><embed width="100%" height="100%" wmode="transparent" quality="slow" style="z-index: 0;" src="../../Images/Flash/loading.swf" type="application/x-shockwave-flash"></embed></div>',
                showLoading: true,
                stop: "<div class='iThinkings-stop' title='Click here to cancel'>&nbsp;</div>",
                showStop: true,
                stop_end: function () { }
            };
            options = $.extend({}, defaults, options);
            var id = options.id;
            var loading = options.loading;
            var showLoading = options.showLoading;
            var stopButton = options.stop;
            var stopImage = options.stop;
            var container = options.container;
            var transparent = options.transparent;
            if (id == "overlay-default") {
                thisObj.Hide({ id: id, container: container });
            }
            var style = "";
            if (container != "body") {
                style = style + ";position: absolute;";
                $(container).css("position", "relative");
                loading = '<div class="iThinkings-loading" style="display:none;"><embed width="100%" height="100%" wmode="transparent" quality="slow" style="z-index: 0;" src="../../Images/Flash/loading.swf" type="application/x-shockwave-flash"></embed></div>';
                stopImage = "<div class='iThinkings-stop' style='display:none;' title='Click here to cancel'>&nbsp;</div>";
            }
            if (!transparent) {
                style = style + ";background-color: #BFBFBF;";
            }
            var ret = new String();
            ret += $.string.Format("<div id='{0}' class='iThinkings-overlay iThinkings-Overlay-CoreSub' style='{1}'>", id, style);
            if (showLoading)
                ret += loading;
            if (options.showStop)
                ret += stopImage;
            ret += "</div>";
            $(container).append(ret);
            //Event
            if (options.showStop) {
                $(container).find(".iThinkings-overlay .iThinkings-stop").click(function (e) {
                    options.stop_end();
                    thisObj.Hide({ container: container });
                });
            }
            //Reposition
            if (container != "body") {
                window.setTimeout(function () {
                    thisObj.Reposition($(container).find(".iThinkings-loading"), { container: $(container), top: -10 });
                    thisObj.Reposition($(container).find(".iThinkings-stop"), { container: $(container), left: 55 });
                    $(container).find(".iThinkings-loading").show();
                    $(container).find(".iThinkings-stop").show();
                }, 500);
            }
            else {
                thisObj.Reposition(".iThinkings-overlay .iThinkings-loading", { top: -5 });
                thisObj.Reposition(".iThinkings-overlay .iThinkings-stop", { left: 55 });
            }
        },
        Hide: function (options) {
            var defaults = {
                id: "",
                container: "body"
            };
            options = $.extend({}, defaults, options);
            var container = options.container;
            var id = options.id;
            if (id) {
                if ($(container).find("#" + id).length) {
                    $(container).find("#" + id).remove();
                }
            }
            else {
                if ($(container).find(".iThinkings-Overlay-CoreSub").length) {
                    $(container).find('.iThinkings-Overlay-CoreSub').remove();
                }
            }
        },
        BuildFunction: function (fn) {
            var ret = eval(fn);
            return ret;
        }
    },
    Init: function () {
        var thisObj = this;

        this.CreateLayout();
        //        this.LoadLayoutColor();
        //        this.ToggleAdvertise();
        //        this.ShowApplicationIcon();
        $('#arrowNorth').click(function () {
            thisObj.ToggleNorth();
        });
        this.WestLayout.Init();
        iThinkings.Layout.ResizeFrameCenter();
    }
};


iThinkings.Navigation = {
    LoadTabId: function (id, $this) {
        if (id) {
            iMarkets.Cookie.TabId(id);
            //tim url tu tabId
            var aObj = $('div a[tabid=' + id + ']') || $('li a[tabid=A' + id + ']') || $('li a[tabid=M' + id + ']') || $('div a[tabid=F' + id + ']');
            var link = $(aObj).attr('link');
            var title = $.trim($(aObj).text());
            var objID = $(aObj).attr('id') || "";
            if (objID.indexOf('Mod_') != -1) {
                var titleApp = $.trim($('ul.accordion li.active a:first').text());
                title = titleApp + '<span> » </span>' + "<span>" + title + "</span>";
            }
            if (objID.indexOf('IFunc_') != -1) {
                var titleApp = $.trim($('ul.accordion li.active a:first').text());
                var titleMod = $.trim($('ul.MenuMod li.active a:first').text());
                title = titleApp + '<span> » </span>' + titleMod + '<span> » </span>' + "<span>" + title + "</span>";
            }
            iMarkets.Layout.LoadUrlToPanelCenter(link, title, $(aObj));
        }
    },
    SelectMenuItem: function ($this, IsNewPage) {
        var url = $.jqURL.url();
        var link = $($this).attr('link');
        var target = $($this).attr('target') || "";
        var tabid = $($this).attr('tabid');
        var pathname = location.pathname.toLowerCase();
        if (pathname.indexOf('front/default.aspx') == -1 && !IsNewPage && tabid) {
            window.location = iMarkets.Server.Host + '../../Mods/Front/default.aspx#tabid=' + tabid;
        }
        if (target == '_self') {
            window.location = iMarkets.Server.Host + link;
        }
        else {
            iMarkets.Navigation.LoadTabId(tabid, $this);
        }

        return false;
    },
    SelectNavigationItem: function (aObj) {
        var link = $(aObj).attr('link');
        var target = $(aObj).attr('target');
        var tabid = $(aObj).attr('tabid');

        $(".iMarkets-ContentBar #iMarkets-Toolbar").remove();
        $(".core-icon").removeClass("core-icon-disabled");


//        //Help
//        $(".core-icon .icon-help").click(function (e) {
//            iMarkets.Core.Toolbar.BuildEvent({
//                name: "help"
//            });
//            e.stopPropagation();
//        });

//        if (target == '_self') {
//            window.location = iMarkets.Server.Host + link;
//        }
//        else {
//            iMarkets.Navigation.LoadTabId(tabid, $(aObj));
//        }
//        $('.icon-refresh,.icon-help').unbind("click");
        //Refresh
        $('.core-icon .icon-refresh').click(function (e) {
            var frameID = "#iMarkets-iFrame";
            $(".iMarkets-iFrame-Container").each(function () {
                if ($(this).css("display") != "none") {
                    frameID = $(this).find("#iMarkets-iFrame");
                }
            });
//            iMarkets.Core.Toolbar.BuildEvent({
//                name: "refresh",
//                frameID: frameID
//            });
//            e.stopPropagation();
        });
        return false;
    },
    ReloadItem: function () {
        var idx = location.hash.replace(/^#tabid=/, '');
        if (idx == '') {
            idx = iMarkets.Cookie.TabId();
            if (idx == undefined || idx == '')
                return true;
        }
        iMarkets.Navigation.LoadTabId(idx);
        $(".iMarkets-ContentBar .core-icon span").not("span.icon-help").remove();
        return false;
    },
    ActiveMenu: function ($this) {
        var url = $.jqURL.url();
        var pathname = location.pathname.toLowerCase();
        if (pathname.indexOf('front/default.aspx') != -1) {
            if (url.lastIndexOf('#tabid=') != -1) {
                var partUrl = url.split('#tabid=');
                $('ul.menu li a span').removeAttr('class');
                $("ul.menu li a[tabid='" + partUrl[1] + "'] span").addClass('active');
            }
            else {
                $('ul.menu li:first a span').addClass('active');
            }
        }
        else if (url.toLowerCase().indexOf('login.aspx') != -1) {
            $(".Navigation-Login ul li a[tabid='86'] span:first").attr('class', 'active');
        }
        else if (url.toLowerCase().indexOf('registration.aspx') != -1) {
            $(".Navigation-Login ul li a[tabid='85'] span:first").attr('class', 'active');
        }
        if ($this) {
            $this.parents("ul").find("li a span").removeClass("active");
            $this.find("span").addClass("active");
        }
    },
    Init: function () {
        var qs = $.getURL("option") || "";
        if (qs == "*") {
            var lblPBHome = iMarkets.Home_ViewerTab.lblPBHome;
            var html = "<li>";
            html += '<a href="javascript:void(0);" link="Mods/Home/default.aspx" target="_self"><span>' + lblPBHome + '</span></a>';
            html += "</li>";
            $("#Navigation").find("ul.menu").append(html);
        }
        this.ActiveMenu();
        $('#Navigation ul.menu li a').click(function () {
            iMarkets.Navigation.SelectMenuItem($(this));
        });
    }
};

iThinkings.Accordion = {

    SelectAccordionMenuItem: function (aObj) {
        iThinkings.Accordion.AppendTextTitle(aObj);
       iThinkings.Accordion.AccessSelectedItem(aObj);
        iThinkings.Accordion.AccessLoadChildItem(aObj);
        //Get Menu Item Text for => Title Form
        iThinkings.Accordion.SelectedItem = aObj[0].childNodes[1].nodeValue;
    },
    //Menu Item Text
    SelectedItem: null,
    AppendTextTitle: function (aObj) {
        if ($(aObj).attr('id').split('_')[0] == 'App')
            $('#topAccordion').html($(aObj).html());
    },
    AccessSelectedItem: function (aObj) {
        // xử lý
        iThinkings.Navigation.SelectNavigationItem(aObj);
    },
    AccessLoadChildItem: function (aObj) {
        var id = $(aObj).attr('id');
        var arr = id.split('_');
        var idType = arr[1];
        var itemType = arr[0];
        var isLoad = $(aObj).attr('isLoad');

        if (isLoad == 0) {
            iThinkings.Accordion.LoadChildItem(idType, itemType);
            switch (itemType) {
                case 'App':
                    $('ul.accordion > li').attr('class', null);
                    break;
                case 'Mod':
                    $('ul.MenuMod > li').attr('class', null);
                    break;
                case 'IFunc':
                    break;
                default: return false;
            }
        }
        switch (itemType) {
            case 'App':
                iThinkings.Cookie.MenuApp(id);
                iThinkings.Cookie.MenuMod(null);
                iThinkings.Cookie.MenuIFunc(null);
                if ($(aObj).parent('li').attr('class') == 'active') {
                }
                else {
                    $('ul.accordion > li').attr('class', null);
                    $(aObj).parent('li').toggleClass('active');
                }
                break;
            case 'Mod':
                iThinkings.Cookie.MenuMod(id);
                iThinkings.Cookie.MenuIFunc(null);
                if ($(aObj).parent('li').attr('class') == 'active') {
                    $(aObj).parent('li').toggleClass('active');
                }
                else {
                    $('ul.MenuMod > li').attr('class', null);
                    $(aObj).parent('li').toggleClass('active');
                }
                break;
            case 'IFunc':
                iThinkings.Cookie.MenuIFunc(id);
                $('div.MenuIFunc a').attr('class', null);
                $(aObj).attr('class', 'active');
                break;
            default: return false;
        }
    },
    LoadChildItem: function (idType, itemType) {
        var jID = '#' + itemType + "_" + idType;
        /// <reference path="../../Css/core/loading/loading_small.gif" />

        $(jID).append('<img src="../../Css/core/loading/loading_small.gif" class="loading" />');
        var jData = "itemType=" + itemType + "&id=" + idType;
        iThinkings.IO.Ajax({
            url: '../Front/Services/TreeFunction.ashx',
            global: false,
            data: jData,
            type: "POST",
            dataType: "html",
            async: false,
            success: function (data) {
                $(jID).parent().append(data);
                $(jID).children(".loading").remove();
                $(jID).attr('isLoad', '1');

                if ($(jID).parent('div').length > 0) {
                    $(jID).attr('class', 'active');
                }
                else {
                    $(jID).parent('li').attr('class', 'active');
                }

                iThinkings.Accordion.SetSize();
            },
            error: function () {
                $(jID).children().remove();
            }
        });
    },
    AutoActiveAccordion: function () {
        if ($("ul.accordion li").size() == 0) {
            return false;
        }
        var url = $.jqURL.url();
        if (url.toLowerCase().indexOf('application.aspx') == -1) {
            return false;
        }
        //Application
        if (iThinkings.Cookie.MenuApp() != undefined) {
            var partApp = iThinkings.Cookie.MenuApp().split('_');
            //Gán titile
            $('#topAccordion').html($('#' + iThinkings.Cookie.MenuApp()).html());
            iThinkings.Accordion.LoadChildItem(partApp[1], partApp[0]);
            //Module

            if (iThinkings.Cookie.MenuMod() != undefined) {

                var partMod = iThinkings.Cookie.MenuMod().split('_');
                iThinkings.Accordion.LoadChildItem(partMod[1], partMod[0]);
                //Interface Function
                if (iThinkings.Cookie.MenuIFunc() != undefined) {
                    var partIFunc = iThinkings.Cookie.MenuIFunc().split('_');
                    iThinkings.Accordion.LoadChildItem(partIFunc[1], partIFunc[0]);
                    var aObj = $('#' + iThinkings.Cookie.MenuIFunc());
                    iThinkings.Navigation.SelectNavigationItem(aObj);
                }
                else {
                    var aObj = $('#' + iThinkings.Cookie.MenuMod());
                    iThinkings.Navigation.SelectNavigationItem(aObj);
                }
            }
            else {
                var aObj = $('#' + iThinkings.Cookie.MenuApp());
                iThinkings.Navigation.SelectNavigationItem(aObj);
            }
        }
        else {
            var aObj = $('ul.accordion li:first-child a');
            var partApp = aObj.attr('id').split('_');
            iThinkings.Cookie.MenuApp(aObj.attr('id'));
            iThinkings.Accordion.AppendTextTitle(aObj);
            iThinkings.Accordion.LoadChildItem(partApp[1], partApp[0]);
        }
    },
    SetSize: function () {
        //Fix iFrame Height
        var northHeight = iThinkingsLayout.state.north.size;
        var westHeight = $(".ui-layout-west").height();
        var accordionHeight = $("ul.accordion > li").size() * ($("ul.accordion li").outerHeight() || 26);
        var fixedAccordion = $(window).height() - northHeight - $("#topAccordion").outerHeight() - accordionHeight - 26;
        $("ul.accordion li.active ul.MenuMod").css("height", "auto");
        $("ul.accordion li.active ul.MenuMod").css("max-height", fixedAccordion + "px");
        $("ul.accordion").css("margin-top", fixedAccordion + "px");
        if ($("ul.accordion > li").size() == 1) {
            $("#arrowWest").hide();
            iThinkingsLayout.options.west.spacing_closed = 0;
            iThinkingsLayout.options.west.spacing_open = 0;
        }
        var top = $(".ui-layout-north").height() + 26;
        $(".ui-layout-west").css("top", top + "px");
        $(".ui-layout-west").height($(window).height() - northHeight - 25)
    },
    Init: function () {
       // this.AutoActiveAccordion();
        this.SetSize();
        $('ul.accordion li a').live('click', function () {
            var $this = $(this);
            iThinkings.Accordion.SelectAccordionMenuItem($this);
            iThinkings.Layout.WestLayout.WestFixed($this);
        });
    }
};
iThinkings.Cookie =
{
    /********************
    *  Get the value of a cookie.                   iThinkings.Cookie.Get('cookie_name');
    *  Set the value of a cookie.                   iThinkings.Cookie.Set('cookie_name', 'the_value');
    *  Delete a cookie by passing null as value.    iThinkings.Cookie.Set('cookie_name', null);
    */
    Set: function (name, value) {
        $.cookie(name, value, { expires: 0.5, path: '/' });
    },
    Get: function (name) {
        return $.cookie(name);
    },
    Property: function (name, value, defaultValue) {
        if (typeof value == 'undefined') {
            var ret = this.Get(name);
            if (ret == null || ret == undefined) {
                return defaultValue;
            }
            else {
                return ret;
            }
        }
        else {
            this.Set(name, value);
            return void (0);
        }
    },
    FirstLoad: function (value) {
        return this.Property('iMarket:FirstLoad', value, null);
    },
    UserPortalID: function (value) {
        return this.Property('iMarket:Session:UserPortalID', value);
    },
    SystemCode: function (value) {
        return this.Property('iMarket:Session:SystemCode', value);
    },
    AnnouncementCode: function (value) {
        return this.Property('iMarket:Session:AnnouncementCode', value);
    },
    UserName: function (value) {
        return this.Property('iMarket:Session:Username', value);
    },
    UserFullName: function (value) {
        return this.Property('iMarket:Session:UserFullName', value);
    },
    ClientGroupID: function (value) {
        return this.Property('iMarket:Session:ClientGroupID', value);
    },
    LanguageId: function (value) {
        return this.Property('iMarket:Session:LanguageID', value, 129);
    },
    SessionId: function (value) {
        return this.Property('iMarket:Session:SessionID', value);
    },
    Culture: function (value) {
        return this.Property('iMarket:Session:Culture', value, 'vi-VN');
    },
    MenuApp: function (value) {
        return this.Property('iMarket:Session:MenuApp', value);
    },
    MenuMod: function (value) {
        return this.Property('iMarket:Session:MenuMod', value);
    },
    MenuIFunc: function (value) {
        if (typeof (value) != 'undefined') {
            this.Property('iMarket:Session:MenuIFunc', value);
           // iThinkings.Session.UpdateLastRequest();
            return void (0);
        }
        else {
            return this.Property('iMarket:Session:MenuIFunc', value);
        }
    },
    Skin: function (value) {
        return this.Property('iMarket:Session:Skin', value);
    },
    ApplicationId: function (value) {
        return this.Property('iMarket:Session:ApplicationID', value);
    },
    Time: function (value) {
        return this.Property('iMarket:Session:Time', value);
    },
    LastAction: function (value) {
        return this.Property('iMarket:Session:LastAction', value);
    },
    TimeOut: function (value) {
        return this.Property('iMarket:Session:TimeOut', value);
    },
    Status: function (value) {
        return this.Property('iMarket:Session:Status', value);
    },
    AdvertiseMode: function (value) {
        return iThinkings.Server.AdvertiseMode;
    },
    UserType: function (value) {
        return this.Property('iMarket:Session:UserType', value);
    },
    UserId: function (value) {
        return this.Property('iMarket:Session:UserID', value);
    },
    ViewMode: function (value) {
        return this.Property('iMarket:Session:ViewMode', value);
    },
    TabId: function (value) {
        if (typeof (value) != 'undefined') {
            this.Property('iMarket:Session:TabId', value);
            //iThinkings.Session.UpdateLastRequest();
            return void (0);
        }
        else {
            return this.Property('iMarket:Session:TabId', value);
        }
    },
    CountryId: function (value) {
        return this.Property('iMarket:Session:CountryId', value);
    },
    FromDateChart: function (value) {
        return this.Property('iMarket:Session:FromDateChart', value);
    },
    ToDateChart: function (value) {
        return this.Property('iMarket:Session:ToDateChart', value);
    },
    UpdateLanguage: function (callback) {
        var url = iThinkings.Server.Host + iThinkings.Service.Url + '/UpdateLanguageUser';
        var pdata = "";
        if (iThinkings.Server.Logged == true) {
            iThinkings.IO.Ajax({
                url: url,
                type: "GET",
                data: {},
                dataType: "xml",
                success: function (data) {
                    if (data && $(data).find("string").length) {
                        data = $(data).find('string').text();
                    }
                    if (typeof callback == "function") {
                        callback();
                    }
                }
            });
        }
        else {
            if (typeof callback == "function") {
                callback();
            }
        }
    },
    UpdateCountryUser: function (countryID) {
        var url = iThinkings.Server.Host + iThinkings.Service.Url + '/UpdateCountryUser';
        if (iThinkings.Server.Logged == true) {
            iThinkings.IO.Ajax({
                url: url,
                type: "GET",
                data: { countryID: countryID },
                contentType: "text/xml; charset=utf-8",
                dataType: "xml",
                success: function (data) {
                    if (data && $(data).find("string").length) {
                        data = $(data).find('string').text();
                    }
                }
            });
        }
    },
    BeforeCloseBrowser: function () {
        window.onunload = function () {
        }
    },
    IsCookieTimeout: function () {
        //compare timeCookie with Server.Time. 
        //     1. >= : 
        //     2. < : time out cookie
        if (iThinkings.Cookie.Time() == "null") {
            return false;
        }
        var diff = (new Date().getTime()) - iThinkings.Cookie.Time();
        if (diff > 15 * 1000) {
            return true;
        }
        return false;
    }
};
$(function () {
    iThinkings.Layout.Init();
    iThinkings.Accordion.Init();
}); ;